<template>
  <div class="login-page">
    <div class="center">
      <img src="../../assets/注册页-注册框背景.png" alt="" class="img_one">
      <div class="login-container">
        <div class="top">
          <div class="title">欢迎您注册</div>
          <img src="../../assets/登录logo.png" alt="" class="img_two">
        </div>

        <div style="margin: 20px" />
        <el-form label-width="90px" :model="user" style="max-width: 60vw" ref="ruleFormRef" :rules="rules" class="form">
          <el-form-item label="用户名:" prop="username">
            <el-input v-model="user.username" placeholder="请输入用户名" label-width="50px" />

          </el-form-item>
          <el-form-item label="密&emsp;码:" prop="password">
            <el-input v-model="user.password" placeholder="请输入密码" type="password" show-password />
          </el-form-item>
          <el-form-item label="确认密码:" prop="psd">
            <el-input v-model="user.psd" placeholder="请输入密码" type="psd" show-password />
          </el-form-item>
          <el-form-item>
            <el-button class="button" type="primary" @click="handleRegister">注册</el-button>
            <el-button class="button" type="primary" @click="handleLogin">已有账号？去登录</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ElMessage } from 'element-plus'
import { reactive, ref } from 'vue'
import { register } from '../../api/register'
import router from '../../router'

// 对称加解密使用到的密钥

const ruleFormRef = ref()
const checked = ref(false)
const user = reactive({
  username: '',
  password: '',
  psd: '',
  checked: false,
})
const rules = reactive({
  username: [
    {
      required: true,
      message: '用户名为必填项!!!',
      trigger: 'blur',
    },
  ],
  password: [
    {
      required: true,
      message: '密码为必填项!!!',
      trigger: 'blur',
    },
  ],
  psd: [
    {
      required: true,
      message: '密码为必填项!!!',
      trigger: 'blur',
    },
  ],
})
// 去登录页面
const handleLogin = async () => {
  router.push('/login')
}

// 注册
const info = localStorage.getItem('register-info')
if (info) {
  const [username, password,psd] = info.split(':::::')
  checked.value = true
  user.username = username
  user.password = password
  user.psd = psd
}
const handleRegister = () => {
  // 这里需要添加注册逻辑
  console.log('注册用户', user.username, user.password,user.psd)
  ElMessage.success('注册成功')
  router.push('/')
}
</script>

<style lang= "less" scoped>
@bg-color: white;

// 嵌套书写
.login-page {

  background: url(../../assets/登录页-背景图.png) no-repeat;
  background-size: cover;
  width: 100%;
  height: 100%;
  position: relative;

  .center {
    width: 100%;
    height: 70vh;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    margin: auto;
  }

  .img_one {
    // width: 30vw;
    width: calc(100% - 65vw);
    height: 70vh;
    position: absolute;
    top: 0;
    left: 231px;
    // animation: move-right 1s linear forwards;
  }

  // img_one 动画
  @keyframes move-right {
    0% {
      transform: translateX(0);
    }

    100% {
      transform: translateX(340px);
    }
  }

  .login-container {
    // width: 30vw;
    width: calc(100% - 65vw);
    height: 70vh;
    position: absolute;
    top: 0;
    right: 231px;
    display: inline;
    opacity: .9;
    background: white;
    padding: 30px;
    padding-top: 60px;
    box-sizing: border-box;
    border-top-right-radius: 25px;
    border-bottom-right-radius: 25px;
    // animation: move-left 1s linear forwards;

    .el-form-item {
      margin-left: 30px;
    }

    // 表单 动画
    @keyframes move-left {
      0% {
        transform: translateX(0);
      }

      100% {
        transform: translateX(-280px);
      }
    }

    .el-input {
      width: 320px;
    }

    .top {
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: space-around;
      margin-bottom: 50px;

      .title {
        font-size: 2.4rem;
        color: black;
        font-family: '思源黑体 CN';
      }

      .img_two {
        width: 120px;
        margin-top: -5px;
      }
    }

    .tip {
      font-size: 1.2rem;
      color: #ccc;
      text-align: center;
    }

    .button {
      width: 20vw;
      height: 5vh;
      color: #FFF;
      font-size: 20px;
      background: #F9B323;
      border: 0;
      border-radius: 10px;
      margin-left: -30px;
      margin-top: 30px;
      margin-bottom: 10px;
    }
  }
}
</style>
